<?php

namespace backend\models;

/**
 * @author  shuang
 * @date    2016-11-16 9:16:55
 * @version V1.0
 * @desc    
 */
use common\models\UserPayRecordHy;
use Yii;
class MY_UserPayRecordHy extends UserPayRecordHy {

    //刷手佣金记录
    public static function getBrushList() {
        $query = MY_UserPayRecordHy::find();
        $query->leftJoin(["userprofile"=>MY_UserProfile::tableName()],"userprofile.userid=me_user_pay_record_hy.userid");
        $query->select("me_user_pay_record_hy.type,me_user_pay_record_hy.class_type,me_user_pay_record_hy.amount,me_user_pay_record_hy.created_at,me_user_pay_record_hy.description,userprofile.username");
        $query->andFilterWhere(["like", "userprofile.username", Yii::$app->request->get("search")]);
        $statusType = Yii::$app->request->post("statusType");
        $begin_at = Yii::$app->request->post("begin_at");
        $end_at = Yii::$app->request->post("end_at");
        if ($statusType > 0) {
            if ($statusType == 1) {
                $class_type = [1, 2];
            }
            if ($statusType == 2) {
                $class_type = [3];
            }
            if ($statusType == 3) {
                $class_type = [2, 3];
            }
            $query->andFilterWhere(["in", "class_type", $class_type]);
        }
        if ($begin_at) {
            $query->andFilterWhere([">=", "created_at", strtotime($begin_at)]);
        }
        if ($end_at) {
            $query->andFilterWhere(["<=", "created_at", strtotime($end_at)]);
        }
        $query->orderBy("me_user_pay_record_hy.created_at desc");
        $countQuery = clone $query;
        $offset = Yii::$app->request->get("offset");
        $limit = Yii::$app->request->get("limit");
        $totalCount = $countQuery->count();
        $res = $query->offset($offset)->limit($limit)->asArray()->all();
        return ["total" => $totalCount, "data" => $res];
    }

}
